<extend name="Base/base" />
<block name="button">
	
	<button class="btn btn-primary" type="submit" form="form"><i class="fa fa-save"></i> {:L('text_save')}</button>
</block>
<block name="breadcrumb">
	<h1>{$heading_title}</h1>
	<ul class="breadcrumb">
		<foreach name="breadcrumb" item="b">
			<li><a href="{:U($b['url'])}">{$b.title}</a></li>
		</foreach>
	</ul>
</block>
<block name="body">
	<if condition="$msg">
		<div class="alert alert-danger alert-dismissible fade in" role="alert">
		      <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
		      {$msg.warning}

		    </div>
	</if>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h4><i class="fa fa-pencil fa-fw"></i>  {$heading_title}</h4>
		</div>
		<div class="panel-body">
			<form action="" method="post" id="form" class="form-horizontal">
				<ul class="nav nav-tabs">
					<li class="active">
						<a href="#tab-general" data-toggle="tab">{:L('text_general')}</a>
					</li>
					<li>
						<a href="#tab-advanced" data-toggle="tab">{:L('text_advanced')}</a>
					</li>
				</ul>
				<div class="tab-content">
					<div class="tab-pane active" id="tab-general">
						<ul class="nav nav-tabs">
							<foreach name="languages" key="key" item="language">
								<li class="{$key?'':'active'}">
									<a href="#language{$language.language_id}" data-toggle="tab"><img src="__PUBLIC__/Images/flags/{$language.image}">  {$language.name}</a>
								</li>
							</foreach>
						</ul>
						<div class="tab-content">
							<foreach name="languages" key="key" item="language">
								<div class="tab-pane {$key?'':'active'}" id="language{$language.language_id}">
									<div class="form-group required">
										<label for="input-title{$language.language_id}" class="col-sm-2 control-label">{:L('entry_title')}</label>
										<div class="col-sm-10">
											<input type="text" name="navigation_description[{$language.language_id}][title]" value="{$navigation['navigation_description'][$language['language_id']]['title']|default=''}" placeholder="{:L('entry_title')}" id="iput-title{$language.language_id}" class="form-control">
											<if condition="isset($msg['title'][$language['language_id']])">
											{:danger_msg($msg['title'][$language['language_id']])}
											</if>
										</div>
									</div>
									
									<div class="form-group">
										<label for="input-description{$language.language_id}" class="col-sm-2 control-label">{:L('entry_description')}</label>
										<div class="col-sm-10">
											<textarea rows="5"  name="navigation_description[{$language.language_id}][description]"  placeholder="{:L('entry_description')}" id="input-description{$language.language_id}" class="form-control">{$navigation['navigation_description'][$language['language_id']]['description']|default=''}</textarea>
											<if condition="isset($msg['description'][$language['language_id']])">
											{:danger_msg($msg['description'][$language['language_id']])}
											</if>
										</div>
									</div>			
								</div>
							</foreach>
						</div>
					</div>
					<div class="tab-pane" id="tab-advanced">						
						<div class="form-group">
							<label for="input-parent" class="col-sm-2 control-label">{:L('entry_parent')}</label>
							<div class="col-sm-10">
								<select name="parent_id" id="input-parent" class="form-control">
									<option value="0">{:L('text_root')}</option>
									<foreach name="navigations" item="item">
										<option value="{$item.navigation_id}" <if condition="isset($navigation['parent_id']) && $item['navigation_id'] eq $navigation['parent_id']">selected</if>>{$item.html}{$item.title}</option>
									</foreach>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label for="input-sort-order" class="col-sm-2 control-label">{:L('entry_sort_order')}</label>
							<div class="col-sm-10">
								<input type="number" class="form-control" value="{$navigation['sort_order']|default=''}"  id="input-sort-order" name="sort_order" placeholder="{:L('entry_sort_order')}">
							</div>					
						</div>
						<div class="form-group required">
							<label for="input-href" class="col-sm-2 control-label">{:L('entry_href')}</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" value="{$navigation.href|default=''}"  id="input-href" name="href" placeholder="{:L('entry_href')}">
								<if condition="isset($msg['href'])">
								{:danger_msg($msg['href'])}
								</if>
								<div class="well">
									<div class="row">
										<div class="col-sm-6">
											<label for="input-article-category" class="control-label">{:L('entry_category')}</label>
											<input type="text" id="input-article-category" class="form-control" name="article_category" placeholder="{:L('entry_category')}">
										</div>
										<div class="col-sm-6">
											<label for="input-article" class="control-label">{:L('entry_article')}</label>
											<input type="text" id="input-article" class="form-control" name="article_title" placeholder="{:L('entry_article')}">
										</div>
										
									</div>
								</div>
							</div>					
						</div>
						<div class="form-group">
							<label for="input-target" class="col-sm-2 control-label">{:L('entry_target')}</label>
							<div class="col-sm-10">
								<select name="target" id="input-status" class="form-control">
									<option value="0">{:L('text_self')}</option>
									<option <if condition="isset($navigation['target']) && ($navigation['target'] eq 1)">selected</if> value="1">{:L('text_blank')}</option>						
								</select>
							</div>					
						</div>
						<div class="form-group">
							<label for="input-status" class="control-label col-sm-2">{:L('text_status')}</label>
							<div class="col-sm-10">
								<select name="status" id="input-status" class="form-control">
									<option value="1">{:L('text_enabled')}</option>
									<option <if condition="isset($navigation['status']) && ($navigation['status'] eq 0)">selected</if> value="0">{:L('text_disabled')}</option>
								</select>
							</div>
						</div>	
					</div>
				</div>
			</form>
		</div>		
	</div>
</block>
<block name="script">
	<script type="text/javascript">
		$(function(){
			//文章分类
			var cateurl='{:U("ArticleCategory/autocomplete")}';
			$('input[name=\'article_category\']').autocomplete({'source': function(request, response) {
					$.ajax({
						url: cateurl + (cateurl.indexOf('?')<0?'?':'&') + 'article_category_title=' +  encodeURIComponent(request),
						dataType: 'json',
						success: function(json) {						
							response($.map(json, function(item) {
								return {
									label: item['title'],
									value: item['article_category_id']
								}
							}));
						}
					});
				},
				'select': function(item) {
					$('input[name=\'article_category\']').val('');

					$('input[name=\'href\']').val('Article/index?article_category_id='+item['value']);
				}
			});
		})
		$(function(){
			var autourl='{:U("Article/autocomplete")}';
			$('input[name=\'article_title\']').autocomplete({'source': function(request, response) {
					$.ajax({
						url: autourl + (autourl.indexOf('?')<0?'?':'&') + 'filter_title=' +  encodeURIComponent(request),
						dataType: 'json',
						success: function(json) {
							response($.map(json, function(item) {
								return {
									label: item['title'],
									value: item['article_id']
								}
							}));
						}
					});
				},
				'select': function(item) {
					$('input[name=\'filter_title\']').val('');
					$('input[name=\'href\']').val('Article/detail?article_id=' + item['value']);
				}
			});
		})
	</script>
</block>